<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Thu, 1 Jan 1970 01:00:00 GMT"); // Date in the past
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
ini_set("display_errors","true");

include_once("file.common.php");
autoheader();
authenticate($validCredentials);

$path = req('path','');
$file = req('file','');

$result = FALSE;
$invalidPath = FALSE;
$ee = '';
$fullPath = webPath($path, $file);
$lastChanged = 0;
$size = 0;

if (strpos($fullPath, '../../') === FALSE)
	$result = file_exists($fullPath);
else
{
	$result = FALSE;
	$invalidPath = TRUE;
}

if ($result) {
	$lastChanged = filemtime($fullPath);
	$size = filesize($fullPath);
}

if ($callback)
	$ee = "$callback({\n";
else
	$ee = "{\n";
$ee .= '"result":' . json_encode($result) . ",\n";
$ee .= '"inactive":' . json_encode($inactive_credentials) . ",\n";
$ee .= '"devServer":' . json_encode($devserver) . ",\n";
$ee .= '"invalidPath":' . json_encode($invalidPath) . ",\n";
$ee .= '"userid":' . json_encode($usercode) . ",\n";
$ee .= '"email":' . json_encode($curateEmail) . ",\n";
$ee .= '"file":' . json_encode($file) . ",\n";
$ee .= '"path":' . json_encode($path) . ",\n";
$ee .= '"fullPath":' . json_encode($fullPath) . ",\n";
$ee .= '"size":' . json_encode($size) . ",\n";
$ee .= '"lastChanged":' . json_encode($lastChanged) . ",\n";
$ee .= '"host":' . json_encode($_SERVER['SERVER_NAME']) . ",\n";
if ($devserver) {
	$ee .= '"cwd":' . json_encode(getcwd()) . ",\n";
	$ee .= '"root":' . json_encode($_SERVER['DOCUMENT_ROOT']) . ",\n";
}
$ee .= '"end":true' . "\n";
if ($callback)
	$ee .= "})";
else
	$ee .= "}";
echo $ee;
?>